// H5 使用了 redux-persist, 主动打开此页面, 来清除在缓存中的数据

import React from 'react';
import Taro from '@tarojs/taro';
import { View, Button } from '@tarojs/components';
import utils from '@/utils';

const ClearStorage = () => {
  const clearPersist = async (type) => {
    if (type === 'all') {
      await Taro.clearStorage();
    } else {
      await Taro.removeStorage({ key: 'persist:redux-persist' });
    }

    Taro.showToast({ title: '清除成功' });
  };

  return (
    <View>
      <Button
        onClick={() => {
          clearPersist();
        }}
      >
        清除 redux-persist
      </Button>
      <Button
        onClick={() => {
          clearPersist('all');
        }}
      >
        清除 全部 storage
      </Button>

      <Button
        onClick={() => {
          let url = utils.getHomePagePath();
          Taro.reLaunch({ url: url + '?now=' + Date.now() });
        }}
      >
        回首页
      </Button>
    </View>
  );
};

export default ClearStorage;
